import 'package:flutter/material.dart';
import 'package:nyh_motorcade_app/styles/colors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'custom_text_field.dart';

typedef ValueCallback = void Function(String value);

class SearchAppBar extends AppBar {
  SearchAppBar({
    required BuildContext context,
    required String hintText,
    required ValueCallback onChanged,
    final TextEditingController? controller,
    final FocusNode? focusNode,
  }) : super(
          elevation: 0,
          titleSpacing: 0,
          backgroundColor: Colours.color_white,
          automaticallyImplyLeading: false,
          title: Container(
            margin: EdgeInsets.only(left: 16.w, right: 6.w),
            child: Row(
              children: [
                Expanded(
                  child: CustomTextField(
                    hintText,
                    controller: controller,
                    focusNode: focusNode,
                    textStyle: TextStyle(color: Colours.color_text_theme, fontSize: 14.sp),
                    hintStyle: TextStyle(color: Colours.color_cfcfd5, fontSize: 14.sp),
                    buildSearchPrefixIcon: true,
                    buildClearSuffixIcon: true,
                    prefixIconPadding: EdgeInsets.symmetric(horizontal: 10.w),
                    suffixIconPadding: EdgeInsets.symmetric(horizontal: 10.w),
                    contentPadding: EdgeInsets.symmetric(vertical: 10.w),
                    fillColor: Colours.color_background,
                    borderRadius: BorderRadius.circular(28.w),
                    textInputAction: TextInputAction.search,
                    onChanged: (value) {
                      onChanged(value);
                    },
                  ),
                ),
                SizedBox(
                  width: 6.w,
                ),
                TextButton(
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  child: Text(
                    "取消",
                    style: TextStyle(color: Colours.color_text_theme, fontSize: 14.sp),
                  ),
                  style: ButtonStyle(
                    tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                    minimumSize: MaterialStateProperty.all(Size(0, 0)),
                    padding: MaterialStateProperty.all(EdgeInsets.all(10)),
                  ),
                ),
              ],
            ),
          ),
        );
}
